/*
 * @Description: 全局错误
 * @Autor: lcz
 * @Date: 2022-11-18 14:44:19
 * @LastEditors: lcz
 * @LastEditTime: 2023-10-08 14:44:12
 */
import { message } from 'antd';

const errorHandler = (error:any) => {
  switch (error.name) {
    case 'local':
      message.error({
        content: error.data.message,
        key: 'process',
        duration: 3,
      });
      break;
    case 'BizError':
      if (error.data.message) {
        message.error({
          content: error.data.message,
          key: 'process',
          duration: 5,
        });
      } else {
        message.error({
          content: 'Business Error, please try again.',
          key: 'process',
          duration: 5,
        });
      }
      break;
    case 'ResponseError':
      message.error({
        content: `${error.response.status} ${error.response.statusText}. Please try again.`,
        key: 'process',
        duration: 5,
      });
      break;
    case 'TypeError':
      message.error({
        content: `Network error. Please try again.`,
        key: 'process',
        duration: 5,
      });
      break;
    default:
      break;
  }

  throw error;
};

export default errorHandler;
